import registerWuJieApp from './micro'
import type { cacheOptions } from 'wujie'
import { DevMicroAppConfig, ProMicroAppConfig } from './config'
import type { Router } from 'vue-router'

export type MicroAppConfig = cacheOptions & {
  title: string
}

export type LocalMicroAppConfig = Omit<cacheOptions, 'name'>

export const microConfig = import.meta.env.DEV ? DevMicroAppConfig : ProMicroAppConfig

/**
 * 注册微前端应用
 */
export function setupMicro(router: Router) {
  if (router) {
    registerWuJieApp(microConfig, router)
  } else {
    console.error('未安装 router')
  }
}
